{% extends "base/base.html" %}

{% block title %}登陆{%endblock%}

{% block content %}
<div class="panel panel-default">
  <div class="panel-heading">
    <ol class="breadcrumb">
      <li><a href="/">主页</a></li>
      <li class="active">登录</li>
    </ol>
  </div>
  <div class="panel-body">
    <div class="alert alert-danger" style="display: none;" role="alert">
      <strong>错误 </strong><span></span>
    </div>
    <form class="form-horizontal" id="login" method="post" action="/login">
      <div class="form-group">
        <label for="username" class="col-sm-2 control-label">用户名</label>
        <div class="col-sm-4">
          <input type="text" class="form-control" id="username">
        </div>
      </div>
      <div class="form-group">
        <label for="password" class="col-sm-2 control-label">密码</label>
        <div class="col-sm-4">
          <input type="password" class="form-control" id="password">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default">登陆</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script>
  $(document).ready(function () {
    $("#login button[type=submit]").click(function () {
      var username = $("#username").val();
      var password = $("#password").val();
    
      $.post("{{ url_for('auth.login') }}", 
        {
          "username": username,
          "password": password
        }, function(data){
          if(data.ret == 20000){
            window.location.href = data.redirect;
          }else{
            $("div[role=alert]").css("display", "block")
            $("div[role=alert] span").html(data.msg)
          }
          console.log(data)
        }).error(function(){
          $("div[role=alert]").css("display", "block")
          $("div[role=alert] span").html("系统错误")
        });
      return false;
    });
  });  
</script>
{% endblock %}

{% block sidebar %}
  {% include "sidebar/about.html" %}
{% endblock %}